package dice.sinanya.db.redis;

import dice.sinanya.db.tools.DbUtil;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import static dice.sinanya.system.MessagesSystem.redisAddress;

public class FlushRedisAddress {
    private static final Logger Log = LogManager.getLogger(FlushRedisAddress.class.getName());

    /**
     * 读取数据库中的骰点历史信息到缓存
     */
    public static void flushRedisAddress() {
        try (Connection conn = DbUtil.getConnection()) {
            String sql = "select * from test.redisAddress";
            try (PreparedStatement ps = conn.prepareStatement(sql)) {
                try (ResultSet set = ps.executeQuery()) {
                    if (set.next()) {
                        redisAddress = set.getString("address");
                    }
                }
            }
        } catch (SQLException e) {
            Log.error(e.getMessage(), e);
        }
    }
}
